package com.shortlink.common.base;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

/**
 * 基础分页请求参数
 *
 * @author wp
 */
@Slf4j
@AllArgsConstructor
@NoArgsConstructor
@Setter
@Getter
public class BasePageReqDTO {
    private static final long DEFAULT_SIZE = 6L;
    private static final long DEFAULT_CURRENT = 1L;
    /**
     * 页大小
     */
    private Long size = DEFAULT_SIZE;
    /**
     * 当前页
     */
    private Long current = DEFAULT_CURRENT;

    public  void setDefaultSize() {
        this.size = DEFAULT_SIZE;
    }

    public void setDefaultCurrent() {
        this.current = DEFAULT_CURRENT;
    }

    /**
     * 校验参数
     */
    public void verify() {
        if (this.size < 1) {
            log.warn(String.format("size(%s) 页面大小不能小于1", this.size));
            setDefaultSize();
        }
        if (this.current < 1) {
            log.warn(String.format("current(%s) 当前页不能小于1", this.current));
            setDefaultCurrent();
        }
    }
}
